package logic

import (
	"context"
	"renting-demo/cart_srv/cart"

	"renting-demo/api/internal/svc"
	"renting-demo/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type PruductRemoveCartLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewPruductRemoveCartLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PruductRemoveCartLogic {
	return &PruductRemoveCartLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *PruductRemoveCartLogic) PruductRemoveCart(req *types.PruductRemoveCartReq) (resp *types.Data, err error) {
	// todo: add your logic here and delete this line
	res, _ := l.svcCtx.CartServer.Remove(context.Background(), &cart.PruductRemoveCartReq{
		UserId:   int64(req.UserId),
		GoodsId:  int64(req.GoodsId),
		GoodsNum: int64(req.GoodsNum),
	})
	if res.Status == "2" {
		return &types.Data{
			Code:    200,
			Message: "整个购物车已删除",
			Data:    nil,
		}, nil
	}
	return &types.Data{
		Code:    200,
		Message: "单个商品已删除",
		Data:    nil,
	}, nil
}
